package com.cy.pj.sys.service.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class SysLogAspect {
    private static final Logger log = LoggerFactory.getLogger(SysLogAspect.class);

    @Pointcut("@annotation(com.cy.pj.common.annotation.RequiredLog)")
    public void doLog(){}

    @Around("doLog()")
    public Object doAround(ProceedingJoinPoint jp)throws Throwable{
        long t1 = System.currentTimeMillis();

        try {
            Object result = jp.proceed();
            long t2 = System.currentTimeMillis();
            log.info("opertime:{}",t2-t1);
            return  result;
        }catch (Throwable e){
            e.printStackTrace();
            long t2 = System.currentTimeMillis();
            log.info("exception:{}",e.getMessage());

            throw  e;
        }
    }
}
